package com.elinkway.infinitemovies.utils;

import android.text.TextUtils;

import com.google.gson.Gson;

import org.json.JSONObject;

import java.util.List;

public class StringUtil {
	private final static String TAG = "StringUtil";
	
	public static String LOCAL_NOTIFICATION_TAG = "showtag";
	
	public static boolean isEmpty(String str) {
		if (TextUtils.isEmpty(str) || (str != null && "".equals(str.trim())||(str != null && "null".equals(str)))) {
			return true;
		}
		
		return false;
	}
	
	public static String getTotalVideoTimeFormat(long videoTotalTime){
		int totalSeconds = (int)(videoTotalTime / 1000L);
		int seconds = totalSeconds % 60;
		int minutes = (totalSeconds / 60) % 60;
		int hours = totalSeconds / 3600;
		return (hours > 0 ? String.format("%02d:%02d:%02d", new Object[] {Integer.valueOf(hours), Integer.valueOf(minutes), Integer.valueOf(seconds)}):
						   String.format("%02d:%02d", new Object[] {Integer.valueOf(minutes), Integer.valueOf(seconds)}));
	}

	/**
	 * json
	 * lihui3
	 * @param c
	 * @param content
	 * @return
	 */
	public static <T> T getJsonObj(Class<T> c, JSONObject content)
	{
		T objT = null;
		Gson gson = new Gson();
		try {
			objT = gson.fromJson(content.toString(), c);
		} catch (Exception e) {
			return null;
		}
		return objT;
	}

	public static String listToString(List list, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			sb.append(list.get(i)).append(separator);
		}
		return sb.toString().substring(0,sb.toString().length()-1);
	}

}
